package requestforwarding;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class SearchStudentServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
//        获取请求的参数
//        发sql语句查询学生信息
//        使用for循环生成查询模拟
        List<Student> studentList = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            int t = i+1;
            studentList.add(new Student("name"+t,18+t,"phone"+t));
        }
//        保存查询结果到Request
        req.setAttribute("student",studentList);
//        请求转发到showStudent.jsp
        req.getRequestDispatcher("/requestforwarding/showStudent.jsp").forward(req,resp);






    }
}
